
%%

figure(1)
close
figure(1)
hold on
set(gcf, 'Units', 'Inches', 'Position',   [4.3472 6.0556 13.5278 6.9444], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
FigName='Known Temperature Comparison';

%subaxis(1,2,1,'Margin',.03,'Spacing',.04,'PaddingBottom',.05)
subaxis(1,2,1,'Spacing',.02,'Margin',0.015,'Padding',0.00,'PaddingLeft',0.04,'PaddingBottom',.033)


hold on


fitness = fitlm(KnownT,MeltingTemp);
fitnessR2 = fitness.Rsquared.Ordinary;
fitnessRMSE = fitness.RMSE;
text(1550,1850,sprintf('R^2=%.2f, RMSE=%.1f^oC',round(fitnessR2,2),fitnessRMSE),'FontName','Times New Roman','FontSize',15);


% Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
      
        zz = i(1);
       plot(KnownT(i), MeltingTemp(i),runningMarkers{zz},'MarkerSize',eval(runningSizesBad{1}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
       
        aaas=aaas+1;
    end
    
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
      plot(KnownT(i), MeltingTemp(i),runningMarkers{zz},'MarkerSize',eval(runningSizes{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
     % text(KnownT(i), MeltingTemp(i)-10,PM_errorStr(i),'HorizontalAlignment','center','VerticalAlignment','top','FontName','Times New Roman','FontSize',13)
 
 
           
            aaas=aaas+1;
        end
        


legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}},'FontName','Times New Roman','FontSize',15,'Location','Best')
%axis equal
box on
ax = gca;
plot([1200 1800],[1200 1800],'-k','handlevisibility','off')
axis([1200 1800 1200 1800])
plot([1200 1900],[1200 1900],'-k','handlevisibility','off')
axis([1200 1900 1200 1900])
set(gca, 'Xtick',1200:50:2000)
set(gca, 'Ytick',1200:50:2000)
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):25:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):25:ax.YLim(2);
set(gca,'ticklength',1.3*[0.0200    0.0500])
axis square

ylabel('RevPet Melting T (\circC)')
xlabel('Experiment Temperature (\circC)')
set(gcf,'Name','Experiment comparison')

% ylabel('PETROGEN 2019 Minimum Mantle Potential Temperature (\circC)')
% xlabel('PRIMELT3 AFM Mantle Potential Temperature (\circC)')
% set(gcf,'Name','PRIMELT3 comparison')

set(gca,'fontsize', 13,'LineWidth',1,'FontName','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')


subaxis(1,2,2)
axis square
hold on
yline(100*MinMgNumPrimary,'k:','Min Mg# melt','LineWidth',2,'LabelHorizontalAlignment','left','handlevisibility','off');
yline(100*MaxMgNumPrimary,'k:','Max Mg# melt','LineWidth',2,'LabelHorizontalAlignment','left','handlevisibility','off');





% Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
      
        zz = i(1);
        plot(100.*KnownMgNum(i),100.* MgnumMelt(i),runningMarkers{zz},'MarkerSize',eval(runningSizesBad{1}),'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
   
        aaas=aaas+1;
    end
    
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
     plot(100.*KnownMgNum(i),100.* MgnumMelt(i),runningMarkers{zz},'MarkerSize',eval(runningSizes{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
       %text(100.*KnownMgNum(i), 100.*MgnumMelt(i)-.5,PM_errorStr(i),'HorizontalAlignment','center','VerticalAlignment','top','FontName','Times New Roman','FontSize',13)
        

 
           
            aaas=aaas+1;
        end
        

ax = gca;

plot([0 100],[0 100],'-k','handlevisibility','off')
axis([57 92 57 92])
set(gca, 'Xtick',0 :2:90)
set(gca, 'Ytick',0 :2:90)
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):1:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);
set(gca,'ticklength',1.3*[0.0200    0.0500])
axis square

ylabel('RevPet Primary Melt Mg#')
xlabel('Input Melt Mg#')

set(gca,'fontsize', 15,'LineWidth',.7,'FontName','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')
set(gcf,'Name',FigName)



%%


figure(2)
close
figure(2)
hold on
set(gcf, 'Units', 'Inches', 'Position',   [4.3472 6.0556 13.5278 6.9444], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
FigName = 'Known Pressure Comparison';



subaxis(1,2,1,'Spacing',.02,'Margin',0.015,'Padding',0.00,'PaddingLeft',0.04,'PaddingBottom',.033)


hold on


fitness = fitlm(KnownP,Pb);
fitnessR2 = fitness.Rsquared.Ordinary;
fitnessRMSE = fitness.RMSE;
text(10,60,sprintf('R^2=%.2f, RMSE=%.1f kbars',round(fitnessR2,2),fitnessRMSE),'FontName','Times New Roman','FontSize',15);




% Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
      
        zz = i(1);
       plot(KnownP(i), Pb(i),runningMarkers{zz},'MarkerSize',eval(runningSizesBad{1}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
       
        aaas=aaas+1;
    end
    
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
      plot(KnownP(i), Pb(i),runningMarkers{zz},'MarkerSize',eval(runningSizes{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
     % text(KnownT(i), MeltingTemp(i)-10,PM_errorStr(i),'HorizontalAlignment','center','VerticalAlignment','top','FontName','Times New Roman','FontSize',13)
 
 
           
            aaas=aaas+1;
        end
        


legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}},'FontName','Times New Roman','FontSize',15,'Location','Best')
%axis equal
box on
ax = gca;
plot([0 80],[0 80],'-k','handlevisibility','off')
axis([0 80 0 80])
% set(gca, 'Xtick',1200:50:1750)
% set(gca, 'Ytick',1200:50:1750)
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):5:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):5:ax.YLim(2);
set(gca,'ticklength',1.3*[0.0200    0.0500])
axis square

ylabel('RevPet Pressure (kbars)')
xlabel('Experiment Pressure (kbars)')
set(gcf,'Name','Experiment comparison')

% ylabel('PETROGEN 2019 Minimum Mantle Potential Temperature (\circC)')
% xlabel('PRIMELT3 AFM Mantle Potential Temperature (\circC)')
% set(gcf,'Name','PRIMELT3 comparison')

set(gca,'fontsize', 15,'LineWidth',0.7,'FontName','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')




subaxis(1,2,2)
axis square
hold on
yline(100*MinMgNumPrimary,'k:','Min Mg# melt','LineWidth',2,'LabelHorizontalAlignment','left','handlevisibility','off');
yline(100*MaxMgNumPrimary,'k:','Max Mg# melt','LineWidth',2,'LabelHorizontalAlignment','left','handlevisibility','off');




yline(100*MinMgNumPrimary,'k:','Min Mg# melt','LineWidth',2,'LabelHorizontalAlignment','left','handlevisibility','off');
yline(100*MaxMgNumPrimary,'k:','Max Mg# melt','LineWidth',2,'LabelHorizontalAlignment','left','handlevisibility','off');





% Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
      
        zz = i(1);
        plot(100.*KnownMgNum(i),100.* MgnumMelt(i),runningMarkers{zz},'MarkerSize',eval(runningSizesBad{1}),'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
   
        aaas=aaas+1;
    end
    
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
     plot(100.*KnownMgNum(i),100.* MgnumMelt(i),runningMarkers{zz},'MarkerSize',eval(runningSizes{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
       %text(100.*KnownMgNum(i), 100.*MgnumMelt(i)-.5,PM_errorStr(i),'HorizontalAlignment','center','VerticalAlignment','top','FontName','Times New Roman','FontSize',13)
        

 
           
            aaas=aaas+1;
        end
        


legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}},'FontName','Times New Roman','FontSize',15,'Location','Best')


ax = gca;
%h=legend([grouplabels(highlight_ReverseFC)','above: PETROGEN hotter'],'FontName','Times New Roman','FontSize',15,'Location','Best')

plot([0 100],[0 100],'-k','handlevisibility','off')
axis([57 92 57 92])
set(gca, 'Xtick',0 :2:90)
set(gca, 'Ytick',0 :2:90)
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):1:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);
set(gca,'ticklength',1.3*[0.0200    0.0500])
axis square

ylabel('RevPet Primary Melt Mg#')
xlabel('Input Melt Mg#')

set(gca,'fontsize', 15,'LineWidth',.7,'FontName','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')
set(gcf,'Name',FigName)



%%
figure(3)
close
figure(3)
hold on
set(gcf, 'Units', 'Inches', 'Position',   [4.3472 6.0556 13.5278 6.9444], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])


FigName='PT OPAM Error';

subaxis(1,2,1,'Spacing',.02,'Margin',0.015,'Padding',0.00,'PaddingLeft',0.04,'PaddingBottom',.033)
        
hold on


fitness = fitlm(KnownP,Pb);
fitnessR2 = fitness.Rsquared.Ordinary;
fitnessRMSE = fitness.RMSE;

%text(10,60,sprintf('R^2=%.2f, RMSE=%.1f kbars',round(fitnessR2,2),fitnessRMSE),'FontName','Times New Roman','FontSize',15);

% Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
      
        zz = i(1);
       %plot(KnownT(i), MeltingTemp(i),runningMarkers{zz},'MarkerSize',eval(runningSizesBad{1}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
        plot(PM_error(i).*100, Pb(i) - KnownP(i), runningMarkers{zz},'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'MarkerSize',eval(runningSizesBad{1}))
   
        aaas=aaas+1;
    end
    
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
        plot(PM_error(i).*100, Pb(i) - KnownP(i), runningMarkers{zz},'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'MarkerSize',eval(runningSizes{zz}))
        
     % plot(KnownT(i), MeltingTemp(i),runningMarkers{zz},'MarkerSize',eval(runningSizes{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
     % text(KnownT(i), MeltingTemp(i)-10,PM_errorStr(i),'HorizontalAlignment','center','VerticalAlignment','top','FontName','Times New Roman','FontSize',13)
 
 
           
            aaas=aaas+1;
        end
        
        
       
%axis equal
box on
ax = gca;
% plot([0 80],[0 80],'-k','handlevisibility','off')
yline(0,'k-');
yline(-3,'k--');
yline(3,'k--');
xline(1,'k-');
% yline(-3,'k--','handlevisbility','off')
%axis([0 30 -20 20 ])
% set(gca, 'Xtick',1200:50:1750)
% set(gca, 'Ytick',1200:50:1750)
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):1:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);
set(gca,'ticklength',1.3*[0.0200    0.0500])
axis square

xlabel('OPLAM error')
ylabel('\Delta P (kbars) [RevPet - Known]')
set(gcf,'Name','Experiment comparison')


set(gca,'fontsize', 15,'LineWidth',0.7,'FontName','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')
xtickformat(ax, 'percentage');

subaxis(1,2,2)
axis square
hold on


% Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
      
        zz = i(1);
       %plot(KnownT(i), MeltingTemp(i),runningMarkers{zz},'MarkerSize',eval(runningSizesBad{1}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
        plot(PM_error(i).*100, MeltingTemp(i) - KnownT(i), runningMarkers{zz},'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'MarkerSize',eval(runningSizesBad{1}))
   
        aaas=aaas+1;
    end
    
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
        plot(PM_error(i).*100,MeltingTemp(i) - KnownT(i), runningMarkers{zz},'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'MarkerSize',eval(runningSizes{zz}))
        
     % plot(KnownT(i), MeltingTemp(i),runningMarkers{zz},'MarkerSize',eval(runningSizes{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerEdgeColor',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}))
     % text(KnownT(i), MeltingTemp(i)-10,PM_errorStr(i),'HorizontalAlignment','center','VerticalAlignment','top','FontName','Times New Roman','FontSize',13)
 
 
           
            aaas=aaas+1;
        end
        
        
h=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}},'FontName','Times New Roman','FontSize',15,'Location','Best','autoupdate','off');

%axis equal
box on
ax = gca;
% plot([0 80],[0 80],'-k','handlevisibility','off')
yline(0,'k-');
yline(-40,'k--');
yline(40,'k--');
xline(1,'k-');
% yline(-3,'k--','handlevisbility','off')
axis([0 30 -100 280 ])
% set(gca, 'Xtick',1200:50:1750)
% set(gca, 'Ytick',1200:50:1750)
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):1:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):10:ax.YLim(2);
set(gca,'ticklength',1.3*[0.0200    0.0500])
axis square

xlabel('OPLAM error')
ylabel('\Delta T (^oC) [RevPet - Known]')

set(gca,'fontsize', 15,'LineWidth',0.7,'FontName','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')
xtickformat(ax, 'percentage');
set(gcf,'Name',FigName)




